#@laybase() 
#define main()


<style>
	#fuioudqModal .modal-body {
		overflow: auto;
	}
	
	#fuioudqModal .modal-body div {
		line-height: 32px;
	}
</style>

<div class="modal fade" id="fuioudqModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">提示</h4>
      </div>
      <div class="modal-body">
                   
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary confirm" data-loading-text="请稍后...">提交</button>
      </div>
    </div>
  </div>
</div>

<div class="col-md-12">
	<a href="/fuioudq/fuiouRecord">交易记录</a>
	<a href="/fuioudq/fuiouSign">签约</a>
	<table class="datatable" id="datatable" data-unique-id="id"></table>
</div>

<script src="/assets/js/bootstrap-table.min.js"></script>
<script src="/assets/js/bootstrap-table-zh-CN.js"></script>
<script>
	$(function(){
		var $table = $('#datatable')
		
		axios.get("/fuioudq/getOrderInfo")
		.then(function(res){
			console.log(res.data)
			var data = res.data,
				titles = [],
				$data = data.data
				
			
			titles.push({
				field: "operation",
				title: "操作"
			})
			
			for(var i = 0;i < $data.length;i++){
				$data[i].id = i
				$data[i].operation = "<a data-id='"+ i +"' href='/fuioudq/fuiouInfo/"+ $data[i].order_id +"' target='_blank'>代扣</a>&nbsp;<a href='javascript:;' data-id='"+ i +"' data-orderid='"+ $data[i].order_id +"' data-toggle='modal' class='lr-hook' data-target='#fuioudqModal'>录入</a>"
			}
			
			for(var i = 0;i < data.names.length;i++){
				titles.push({
					field: data.fields[i],
					title: data.names[i]
				})
			}
			
			createTable(titles,$data)
		})
		
		//创建表格
		function createTable(titles,data){
			$table.bootstrapTable({
				uniqueId: 'id',	
				search: true,
				pagination: true, 
	            pageSize: 20,
	            toolbar: '#toolbar',
			    columns: titles,
			    data: data,
			    sortStable:true
			});		
		}
		
		var modalDom = $("#fuioudqModal"),
			modalBody = modalDom.find(".modal-body"),
			modalTitle = modalDom.find(".modal-title"),
			modalConfirm = modalDom.find(".confirm");
		modalBody.css("height",$(window).height() * .78)
		$table.on("click","a",function(){
			var that = $(this),
				uniqueId = that.data("id")
			modalConfirm.data("orderid",that.data("orderid"))
			
			if(that.hasClass("dk-hook")){
				modalTitle.html("代扣")
				modalConfirm.data("suburl",1)
				/*axios.get("/fuioudq/celpay",{
					params: {
						orderId: that.data("orderid")
					}
				})
				.then(function(res){
					console.log(res.data)
				})*/
			}else{
				modalTitle.html("录入")
				modalConfirm.data("suburl",2)
				/*axios.get("/fuioudq/projectApply",{
					params: {
						orderId: that.data("orderid")
					}
				})
				.then(function(res){
					console.log(res.data)
				})*/
			}
			randerMsg(uniqueId)
		})
		
		function randerMsg(uniqueId){
			var rowData = $table.bootstrapTable('getRowByUniqueId',uniqueId),
				html = "<div><span>订单号：</span><span>"+ rowData.order_id +"</span></div>"+
					   "<div><span>总行名称：</span><span>"+ rowData.bankName +"</span></div>"+
					   "<div><span>客户姓名：</span><span>"+ rowData.name +"</span></div>"+
					   "<div><span>运营商：</span><span>"+ rowData.operator +"</span></div>"+
					   "<div><span>区域：</span><span>"+ rowData.area +"</span></div>"+
					   "<div><span>客户电话：</span><span>"+ rowData.phone +"</span></div>"+
					   "<div><span>身份证号码：</span><span>"+ rowData.idNo +"</span></div>"+
					   "<div><span>银行帐号：</span><span>"+ rowData.bankAccount +"</span></div>"+
					   "<div><span>序列号：</span><span>"+ rowData.serailNo +"</span></div>"+
					   "<div><span>贷款金额：</span><span>"+ rowData.loanAmt +"</span></div>"+
					   "<div><span>总还款金额：</span><span>"+ rowData.amt +"</span></div>"+
					   "<div><span>月还款金额：</span><span>"+ rowData.monthlyRepayAmt +"</span></div>"+
					   "<div><span>总期限（天）：</span><span>"+ rowData.deadline +"</span></div>"+
					   "<div><span>期数：</span><span>"+ rowData.term +"</span></div>"+
					   "<div><span>合同编号：</span><span>"+ rowData.bargainNo +"</span></div>"+
					   "<div><span>项目id：</span><span>"+ rowData.projectId +"</span></div>"+
					   "<div><span>签约日期：</span><span>"+ rowData.signDate +"</span></div>"+
					   "<div><span>放款日期：</span><span>"+ rowData.lendingDate +"</span></div>"+
					   "<div><span>到期日期：</span><span>"+ rowData.expiryDate +"</span></div>";
			modalBody.html(html)
		}
		
		modalConfirm.click(function(){
			var that = $(this),
				suburl = that.data("suburl")
			that.button('loading')
			if(suburl == 1){
				/*axios.get("/fuioudq/celpay",{
					params: {
						orderId: that.data("orderid")
					}
				})
				.then(function(res){
					console.log(res.data)
					if(res.data.code == "0000"){
						_x.show_alert_sh(res.data.msg,true)
					}else{
						_x.show_alert_sh(res.data.msg,false)
					}
					modalDom.modal('hide')
					that.button('reset')
				})
				.catch(function(){
					that.button('reset')
					_x.show_alert_sh("代扣失败，请稍后重试！",false)
				})*/
			
			}else if(suburl == 2){
				axios.get("/fuioudq/projectApply",{
					params: {
						orderId: that.data("orderid")
					}
				})
				.then(function(res){
					console.log(res.data)
					if(res.data.code == "0000"){
						_x.show_alert_sh(res.data.msg,true)
					}else{
						_x.show_alert_sh(res.data.msg,false)
					}
					modalDom.modal('hide')
					that.button('reset')
				})
				.catch(function(){
					that.button('reset')
					_x.show_alert_sh("录入失败，请稍后重试！",false)
				})
			}else{
				that.button('reset')
			}
		})
	})
</script>
#end